import type { MenuDataItem } from '@ant-design/pro-layout';
import { getMenuData, getPageTitle } from '@ant-design/pro-layout'; // DefaultFooter
import { Helmet, HelmetProvider } from 'react-helmet-async';
import type { ConnectProps } from 'umi';
import { Link, useIntl, connect } from 'umi'; // FormattedMessage
import React from 'react';
import type { ConnectState } from '@/models/connect';
import logo from '../../public/favicon.png';
import IconsCompany from '../../public/icons/company.png';
import Icons360 from '../../public/icons/360.png';
import IconsFirefox from '../../public/icons/firefox.png';
import IconsGoogle from '../../public/icons/google.png';
import IconsIE from '../../public/icons/ie.png';
import IconsQQ from '../../public/icons/qq.png';
import IconsSG from '../../public/icons/sg.png';
import styles from './UserLayout.less';

export type UserLayoutProps = {
  breadcrumbNameMap: Record<string, MenuDataItem>;
} & Partial<ConnectProps>;

const UserLayout: React.FC<UserLayoutProps> = (props) => {
  const {
    route = {
      routes: [],
    },
  } = props;
  const { routes = [] } = route;
  const {
    children,
    location = {
      pathname: '',
    },
  } = props;
  const { formatMessage } = useIntl();
  const { breadcrumb } = getMenuData(routes);
  const title = getPageTitle({
    pathname: location.pathname,
    formatMessage,
    breadcrumb,
    ...props,
  });
  return (
    <HelmetProvider>
      <Helmet>
        <title>科研管理系统</title>
        <meta name="description" content={title} />
      </Helmet>

      <div className={styles.container}>
        <div className={styles.header}>
          <Link to="/">
            <img alt="logo" className={styles.logo} src={logo} />
          </Link>
          <div className={styles.header_hospital}>
            <div className={styles.header_hospital_name}>上海市人民医院</div>
            <div className={styles.header_hospital_en}>SHANG HAI GENERAL HOSPITAL</div>
          </div>
          <span className={styles.title}>科研管理系统</span>
          <div className={styles.header_space}></div>
          <div className={styles.header_navigation}>
            <Link to="/main/home4?style=1">
              <span>临床研究一网通</span>
            </Link>
            <Link to="/user-info/list">
              <span>专业</span>
            </Link>
            <Link to="/">
              <span>智慧</span>
            </Link>
            <Link to="/">
              <span>高效</span>
            </Link>
            <Link to="/">
              <span>便捷</span>
            </Link>
            <Link to="/">
              <span>规范</span>
            </Link>
          </div>
        </div>
        <div className={styles.login_content}>{children}</div>
        <div className={styles.footer}>
          <Link to="/">
            <img className={styles.footer_icons_company} alt="logo" src={IconsCompany} />
          </Link>
          <span className={styles.footer_company_name}>上海润银软件有限公司</span>
          <span className={styles.footer_technical_support}>技术支持</span>
          <div className={styles.footer_space}></div>
          <span className={styles.footer_browser_support}>浏览器支持</span>
          <img className={styles.footer_browser} alt="logo" src={IconsFirefox} />
          <img className={styles.footer_browser} alt="logo" src={Icons360} />
          <img className={styles.footer_browser} alt="logo" src={IconsGoogle} />
          <img className={styles.footer_browser} alt="logo" src={IconsQQ} />
          <img className={styles.footer_browser} alt="logo" src={IconsSG} />
          <img className={styles.footer_browser} alt="logo" src={IconsIE} />
          <span className={styles.footer_browseDescription}>（IE8以上）</span>
        </div>
      </div>
    </HelmetProvider>
  );
};

export default connect(({ settings }: ConnectState) => ({ ...settings }))(UserLayout);
